#' Ready for a Single Country data
#'
#' @description 获得单个国家的VAR回归数据，同时，数据不平稳，则差分处理
#' @param regdata a data frame which include \code{ID, Time, cpi, gdp, TFP, unctn}
#' @param FV a list which include every country's foreign variables
#' @param country
#' @param endovar a charactor vector, endogenous variable's names
ReadySingleCountry <- function(regdata, FV, country = 'ARG',endovar = c('cpi','gdp','TFP')){
  vardata <- regdata[regdata$ID %in% country,c('Time',endovar)] %>%
    cbind(FV[[country]][,paste(country, endovar,'_FL0',sep = '')])

  # ADF test
  pvalue <- NULL
  for (i in 2:ncol(vardata)) {
    a <- CADFtest::CADFtest(vardata[,i],type = 'drift',criterion = 'AIC')
    pvalue <- data.frame(cnt = country, var = names(vardata)[i], pvalue = a$p.value) %>% rbind(pvalue,.)
    if (a$p.value > 0.05) {
      sprintf('%s, %s, %f',country,names(vardata)[i],a$p.value) %>% print()
      vardata[,i] <- c(NA,diff(vardata[,i]))
      # vardata[13,i] <- vardata[14,i]
    }
  }
  vardata <- merge(vardata,regdata[regdata$ID %in% 'USA',c('Time','unctn')],by = 'Time',all.x = T) %>%
    .[-1,-1]
  return(list(vardata = na.omit(vardata), ADF = pvalue))
}
